import Vue from 'vue'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import router from './router.js'
import store from './store.js'
import App from './App.vue'
import API from "./api/index.js"
Vue.use(ElementUI);
import { MessageBox } from 'element-ui';
Vue.config.productionTip = false
Vue.prototype.API = API;//接口
//设置动态title
// router.beforeEach((to,from,next)=>{
//   /*路由发生变化修改页面title */
//   if(to.meta.title){
//     document.title = to.meta.title
//   }else{
//     document.title = 'title'
//   }
//   next()
// })
router.beforeEach((to, from, next) => {
  
  // 需要登录才允许进入路由
  if(to.meta.requiresAuth){
      // 判断是否登录
      if(sessionStorage.getItem('user')){
          next();
      }else{
        console.log('路由:'+to.meta.requiresAuth);
        MessageBox.confirm('请先登录?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            next({
                path:'/login'
            })
          }).catch(() => {
            // this.$message({
            //   type: 'info',
            //   message: '已取消删除'
            // });          
          });
          
      }
  }else{
      // 调用next()方法，放行路由跳转
      next();
  }

});
new Vue({
  router,
  store,
  render: h => h(App),
}).$mount('#app')
